import entryFactory from 'bpmn-js-properties-panel/lib/factory/EntryFactory';
import {
  is
} from 'bpmn-js/lib/util/ModelUtil';
import uuid from 'uuid'
import {FormComponent} from "../../../form/form.component";


export default function (group, element, translate) {

  if (is(element, 'bpmn:StartEvent') || is(element, 'bpmn:Task')) {
    let formId = element.businessObject.get('flowable:formKey');
    if (!formId) {
      formId = uuid.v4();
      element.businessObject.set('flowable:formKey', formId);
    }

    group.entries.push(entryFactory.link({
      id: 'formEdit',
      description: translate('Describe For Form'),
      label: translate('Edit Form'),
      handleClick: function (element) {
        FormComponent.open(formId);
      },
    }));
    // FormComponent.getProperties(formId, (value) => {
    //   group.entries.push(entryFactory.table({
    //     id: 'properties',
    //     labels: ['显示名称', '数据项'],
    //     modelProperties: ['label', 'field'],
    //     getElements: (element, node) => {
    //       return value;
    //     }
    //   }));
    // });
    group.entries.push(entryFactory.textField({
      id: 'formKey',
      modelProperty: 'flowable:formKey',
      hidden: function () {
        return true;
      },
      get: function () {
        return {'flowable:formKey': formId};
      }
    }));
  }
}
